package com.AAA.controller.fpa;

import com.AAA.entity.LayData;
import com.AAA.entity.MyPage;
import com.AAA.entity.User;
import com.AAA.entity.fpa.TFpaPlane;
import com.AAA.service.fpa.ITFpaPlaneService;
import com.github.pagehelper.PageInfo;
import org.springframework.web.bind.annotation.*;
import org.springframework.beans.factory.annotation.Autowired;

import javax.servlet.http.HttpSession;
import java.util.Date;

/**
 * (TFpaPlane)表控制层
 *
 * @author 何泽明
 * @since 2022-11-05 16:19:30
 */
@RestController
@RequestMapping("tFpaPlane")
public class TFpaPlaneController {
    /**
     * 服务对象
     */
    @Autowired
    private ITFpaPlaneService service;

    //分页
    @RequestMapping("queryAll")
    public LayData queryAll(MyPage myPage, TFpaPlane tFpaPlane){
        PageInfo pageInfo=service.query(myPage,tFpaPlane);
        return new LayData(pageInfo);
    }


    //添加 and 修改
    @RequestMapping("add")
    public LayData add(TFpaPlane tFpaPlane, HttpSession session){
        User user = (User) session.getAttribute("user");
        tFpaPlane.setCreatetime(new Date());
        tFpaPlane.setUid(user.getId());
        if (tFpaPlane.getId()==null){
            tFpaPlane.setCreatetime(new Date());
            return new LayData(service.add(tFpaPlane));
        }else {
            tFpaPlane.setUpdatetime(new Date());
            return new LayData(service.edit(tFpaPlane));
        }
    }

    //状态
    @ResponseBody
    @PostMapping("updates")
    public LayData delete(TFpaPlane tFpaPlane){
        boolean status=service.updates(tFpaPlane);
        return new LayData(status);
    }

    @GetMapping("getByCode")
    public LayData queryByQyCode(TFpaPlane tFpaPlane){
        return new LayData(service.queryByQyCode(tFpaPlane));
    }

}

